home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / lisp / kcl / akcl / akcl1615.lha / doc / bignum < prev    next >
Lisp/Scheme  |  1991-04-08  |  2KB  |  61 lines

  1.  
  2.  
  3. A directory mp was added to hold the new multi precision arithmetic
  4. code.  The layout and a fair amount of code in the mp directory is an
  5. enhanced version of gpari version 34. The gpari c code was rewritten
  6. to be more efficient, and gcc assembler macros were added to allow
  7. inlining of operations not possible to do in C.  On a 68K machine,
  8. this allows the C version to be as efficient as the very carefully
  9. written assembler in the gpari distribution.  For the main machines,
  10. an assembler file (produced by gcc) based on this new method, is
  11. included.   This is for sites which do not have gcc, or do not
  12. wish to compile the whole system with gcc.
  13.  
  14. Bignum arithmetic is much faster now.  Many changes were made to
  15. cmpnew also, to add 'integer' as a new type.  It differs from
  16. variables of other types, in that storage is associated to each such
  17. variable, and assignments mean copying the storage.  This allows a
  18. function which does a good deal of bignum arithmetic, to do very
  19. little consing in the heap.  An example is the computation of PI-INV
  20. in scratchpad, which calculates the inverse of pi to a prescribed
  21. number of bits accuracy.  That function is now about 20 times faster,
  22. and no longer causes garbage collection.  In versions of AKCL  where
  23. HAVE_ALLOCA is defined, the temporary storage growth is on the C
  24. stack, although this often not so critical (for example it makes
  25. virtually no difference in the PI-INV example, since in spite of the
  26. many operations, only one storage allocation takes place.
  27.     
  28. Below is the actual code for PI-INV
  29.  
  30. On a sun3/280 (cli.com)
  31.  
  32. Here is the comparison of lucid and akcl before and after
  33. on that pi-inv.   Times are in seconds with multiples of the
  34. akcl time in parentheses.
  35.  
  36. On a sun3/280 (cli.com)
  37.  
  38. pi-inv   akcl-566  franz        lucid         old kcl/akcl
  39. ----------------------------------------
  40. 10000      3.3     9.2(2.8 X)  15.3 (4.6X)    92.7   (29.5 X)
  41. 20000      12.7    31.0(2.4 X) 62.2 (4.9X)    580.0  (45.5 X)
  42.  
  43.  
  44. (defun pi-inv (bits &aux (m 0))
  45.   (declare (integer bits m))
  46.   (let* ((n (+ bits (integer-length bits) 11))
  47.          (tt (truncate (ash 1 n) 882))
  48.          (d (* 4 882 882))
  49.          (s 0))
  50.     (declare (integer s d tt n))
  51.     (do ((i 2 (+ i 2))
  52.          (j 1123 (+ j 21460)))
  53.         ((zerop tt) (cons s (- (+ n 2))))
  54.       (declare (integer i j))
  55.         (setq s (+ s (* j tt))
  56.               m (- (* (- i 1) (- (* 2 i) 1) (- (* 2 i) 3)))
  57.               tt (truncate (* m tt) (* d (the integer (expt i 3))))))))
  58.  
  59.  
  60.  
  61.